<template>
  <div class="tabbar-container">
    <div class="tabbar" id="tabbar">
      <van-tabbar v-model="active" active-color="#ee0a24">
        <!-- <van-tabbar-item badge="3"> -->
        <van-tabbar-item @click="setActive(0)">
          <span>首页</span>
          <template #icon="props">
            <van-icon name="wap-home-o" />
            <!-- <img :src="props.active ? icon.active : icon.inactive" /> -->
          </template>
        </van-tabbar-item>
        <van-tabbar-item @click="setActive(1)" icon="bar-chart-o"
          >排行榜</van-tabbar-item
        >
        <van-tabbar-item @click="setActive(2)" icon="newspaper-o"
          >活动说明</van-tabbar-item
        >
        <van-tabbar-item @click="setActive(3)" icon="search"
          >搜索</van-tabbar-item
        >
      </van-tabbar>
    </div>
  </div>
</template>

<script>


export default {
  name: "TabBar",
  data() {
    return {
      activeIndex: 0,
      active: 0,
      icon: {
        active: "https://img01.yzcdn.cn/vant/user-active.png",
        inactive: "https://img01.yzcdn.cn/vant/user-inactive.png",
      },
    };
  },
  methods: {
    setActive(index) {
      this.activeIndex = index;
      this.$emit("change", index); // 触发事件，通知父组件切换页面
    },
  },
};
</script>

<style scoped>
.tabbar-container {
    height: 60px;
  width: 100%;
  position: relative;
}

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50px;
  background-color: white;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  display: flex;
  z-index: 100;
}

.tabbar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #888888;
  font-size: 12px;
  transition: all 0.3s ease;
  cursor: pointer;
}

.tabbar-item.active {
  color: #00c48c;
}

.tabbar-icon {
  font-size: 20px;
  margin-bottom: 4px;
}
</style>
